<template>
  <div>
    <h2>添加</h2>
    <table>
      <tbody>
        <tr>
          <td>账号</td>
          <td>
            <input type="text" v-model="form.name" />
          </td>
        </tr>
        <tr>
          <td>密码</td>
          <td>
            <input type="password" v-model="form.pwd" />
          </td>
        </tr>
        <tr>
          <td>房号名称</td>
          <td>
            <input type="text" v-model="form.fangname" />
          </td>
        </tr>
        <tr>
          <td>状态</td>
          <td>
            <input type="text" v-model="form.zhuangtai" />
          </td>
        </tr>
        <tr>
          <td></td>
          <td>
            <button @click="Add">添加</button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import "bootstrap/dist/css/bootstrap.min.css";

const router = useRouter();
const form = reactive({
  id: 0,
  name: "",
  pwd: "",
  fangname: "",
  zhuangtai: "",
});

const Add=()=>{
    if(!form.name){
        alert("不能为空")
        return;
    }
    axios.post("https://localhost:7293/api/fanghao/Addfang",form).then(res=>{
        if(res.data>0){
            alert("添加成功");
            router.push("login");
        }
        else
        {
            alert("添加失败")
        }
    })
}

</script>

<style scoped></style>
